// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { game } from "../../../../script/game/control/game";
import { lineType } from "../../../../script/game/gameType";
import { ccs } from "../../../../script/util/services";
import { touchExd } from "../../../../script/util/TouchExtend";
import { WinBase } from "../../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

//生产线类
@ccclass
export default class NewClass extends WinBase {

    @property(cc.Label)
    workers: cc.Label = null;

    @property(cc.Label)
    make: cc.Label = null;

    @property(cc.Label)
    stock: cc.Label = null;

    @property(cc.Label)
    material: cc.Label = null;
    //状态
    @property(cc.Label)
    state: cc.Label = null;

    @property(cc.Node) 
    line: cc.Node = null;

    @property(cc.Node) 
    manager: cc.Node = null;

    @property(cc.Animation)
    anim: cc.Animation = null;
    
    data: any = null;
    stateCode: number = 1;
    id = 0;
    type = "";
    start () {
    }

    setData(data: lineType, id, type) {
        this.id = id;
        this.data = data;
        this.type = type;
        let item = game.playerMgr.bag.companyBag.getItem(id);
        if(type == "make") {
             this.make.string = "最大产能：" + ccs.gf.getOmitNum(item.company.makeType.month);
             this.stock.string = "库存：" + ccs.gf.getOmitNum(item.company.productCount);
        } else {
            this.make.string ="最大市场：" +  ccs.gf.getOmitNum(item.company.salesType.month);
        }
        this.workers.string = "员工：" + ccs.gf.getOmitNum(data.count) + "人";
        this.state.string = data.state == 1? "运营": "休息";
        if(this.data && this.data.state == 1) {
            this.startAni();
        }
    }
    startAni() {
        let product = cc.tween()
        .to(1, { position: cc.v2(231, -1),  scale: 1, opacity: 255 })
        .to(0.1, { opacity: 0 })
        .to(0.1, { position: cc.v2(-228.255, 0), scale: 0.5 })
        
        this.line.children.forEach((val, index) => {
            cc.Tween.stopAllByTarget(val);
            this.scheduleOnce(() => {
                this.setAni(val, product);
            },index * 0.5);
        })
    }
    setAni(node: cc.Node, ani1) {
        ani1.clone(node).call(() => {
            if(this.stateCode) {
                this.setAni(node, ani1);
            }
        })
        .start();
    }
    stop() {
        this.stateCode = 0;
    }
    // update (dt) {}
}
